'''
Created on Jul 20, 2010

@author: riche
'''

import re

class Message(object):
    
    def __init__(self, body=''):
        self.__body__ = body
        if body != '':
            self.parse_msg()
            
    def parse_msg(self, body=''):
        if body != '':
            self.__body__ = body
        m = re.search('(\S+):([0-9]+):(\S+\s*)', self.__body__)
        self._node_name = m.group(1)
        self.time_stamp = m.group(2)
        self.content = m.group(3)
        return (self._node_name, self.content)

    def create_msg_body(self, node_name, time_stamp, content):
        self._node_name = node_name
        self.content = content
        self.time_stamp = int(time_stamp)
        self.__body__ = '{}:{}:{}'.format(node_name, int(time_stamp), content)
        
    def get_body(self):
        return self.__body__